package nowCoder;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class HJ43 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[][] maze = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                maze[i][j] = in.nextInt();
            }
        }
        List<Dian> list = new ArrayList<>();
        // 起始点（0，0）
        list.add(new Dian(0,0,null));
        Dian dian;
        ln:
        while(true){
            List<Dian> nei = new ArrayList<>();
            for (Dian th : list) {
                int x = th.x;
                int y = th.y;
                // 当当前点为终点时结束查找，这里在点移动之后就可以判断了
                if (x == n-1 && y == m-1){
                    dian = th;
                    break ln;
                }
                // 判断点是否合规，合规的点进入记录为下次搜索的起始点
                Dian right = new Dian(x+1,y,th);
                if (!T(right,n,m,maze) && (th.last == null || right.x != th.last.x))
                    nei.add(right);
                Dian left = new Dian(x-1,y,th);
                if (!T(left,n,m,maze) && (th.last == null || left.x != th.last.x))
                    nei.add(left);
                Dian up = new Dian(x,y-1,th);
                if (!T(up,n,m,maze) && (th.last == null || up.y != th.last.y))
                    nei.add(up);
                Dian down = new Dian(x,y+1,th);
                if (!T(down,n,m,maze) && (th.last == null || down.y != th.last.y))
                    nei.add(down);
            }
            list = nei;
        }
        // 获取到终点后，通过last的上级点来反向输出坐标
        List<String> lll = new ArrayList<>();
        while(true){
            lll.add("("+dian.x+","+dian.y+")");
            if (dian.x == 0 && dian.y == 0){
                break;
            }
            dian = dian.last;
        }
        for (int i = lll.size() - 1; i >= 0; i--) {
            System.out.println(lll.get(i));
        }
    }
    // 判断当前点是否符合规定，及当前点值是0同时点坐标不可超出数组边界
    public static boolean T(Dian dian, int n, int m, int[][] maze){
        return dian.x < 0 || dian.x >= n || dian.y < 0 || dian.y >= m || maze[dian.x][dian.y] == 1;
    }
    // 记录当前点位置，以及当前点是从哪个位置过来的
    static class Dian{
        int x;
        int y;
        Dian last;
        public Dian(int x, int y, Dian last) {
            this.x = x;
            this.y = y;
            this.last = last;
        }
    }
}
